1 module hip.api.graphics.g2d.g2d_binding;
2 public import hip.api.data.commons;
3 public import hip.api.renderer.operations;
4 public import hip.api.graphics.color;
5 public import hip.api.graphics.g2d.animation;
6 public import hip.api.renderer.viewport;
7 public import hip.api.data.font;
8 public import hip.api.data.tilemap;
9 public import hip.api.graphics.text;
10 
11 version(Have_util) version = ImportSpritesheet;
12 
13 version(ImportSpritesheet)
14 {
15     public import hip.util.data_structures : Array2D, Array2D_GC;
16     public alias Spritesheet = Array2D_GC!IHipTextureRegion;
17 }
18 
19 version(DirectCall)
20 {
21     public import hip.graphics.g2d.renderer2d;
22 }
23 else version(ScriptAPI)
24 {
25     void initG2D()
26     {
27         import hip.api.internal;
28         import hip.api.console;
29         loadClassFunctionPointers!HipG2DBinding;
30         log("HipengineAPI: Initialized G2D");
31     }
32 
33     class HipG2DBinding
34     {
35         extern(System) __gshared //All functions there will be loaded
36         {
37             ///Use this only when you're sure you don't need!
38             void function(bool enable = true) setRendererErrorCheckingEnabled;
39 
40             ///Will change the color for the next calls to drawPixel, drawRectangle, drawTriangle, fillRectangle, fillTriangle, drawLine, drawQuadraticBezierLine
41             void function(HipColor color) setGeometryColor;
42             ///Draw a pixel at (x, y) with the color specified at setGeometryColor
43             void function(int x, int y, HipColor color = HipColor.no) drawPixel;
44             ///Draws an unfilled rectangle
45             void function(int x, int y, int w, int h, HipColor color = HipColor.no) drawRectangle;
46             ///Draws an unfilled triangle
47             void function(int x1, int y1, int x2, int y2, int x3, int y3, HipColor color = HipColor.no) drawTriangle;
48             ///Draws a filled rectangle
49             void function(int x, int y, int w, int h, HipColor color = HipColor.no) fillRectangle;
50             ///Draws a filled rectangle with rounded borders
51             void function(int x, int y, int w, int h, int radius = 4, HipColor color = HipColor.no, int precision = 16) fillRoundRect;
52             ///Draws a filled triangle
53             void function(int x1, int y1, int x2, int y2, int x3, int y3, HipColor color = HipColor.no) fillTriangle;
54             ///Draws unfilled circle
55             void function(int x, int y, int radiusW, int radiusH, int degrees = 360, HipColor color = HipColor.no, int precision = 24) drawEllipse;
56             ///Draws a filled circle
57             void function(int x, int y, int radiusW, int radiusH, int degrees = 360, HipColor color = HipColor.no, int precision = 24) fillEllipse;
58             ///Draws a line from (x1, y1) to (x2, y2)
59             void function(int x1, int y1, int x2, int y2, HipColor color = HipColor.no) drawLine;
60             ///Draws a line using bezier points. The higher the precision, the smoother the line, the heavier it is to execute
61             void function(int x0, int y0, int x1, int y1, int x2, int y2, int precision=24, HipColor color = HipColor.no) drawQuadraticBezierLine;
62             ///Draws the target sprite instance
63             void function(IHipTexture texture, ubyte[] vertices) drawSprite;
64             ///Draws a texture at a specified place
65             void function(IHipTexture reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawTexture;
66             ///Draws a texture region at a specified place
67             void function(IHipTextureRegion reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawRegion;
68             void function(IHipTilemap reg) drawMap;
69             ///Sets the font for the next drawText commands
70             void function (IHipFont font) setFont;
71             ///Sets the font using HipAssetManager.loadFont
72             package void function (IHipAssetLoadTask font) setFontDeferred;
73             ///Changes textBatch state to use this color
74             void function(HipColor) setTextColor;
75             ///Draws a text using the last font set
76             void function(string text, int x, int y, HipColor color = HipColor.white, HipTextAlign alignH = HipTextAlign.CENTER, HipTextAlign alignV = HipTextAlign.CENTER, int boundsWidth = -1, int boundsHeight = -1, bool wordWrap = false) drawText;
77             ///Draw text using those vertices. Low level API
78             void function(void[] vertices, IHipFont font)  drawTextVertices;
79 
80 
81             
82             ///Sets active the viewport passed
83             void function(Viewport v) setViewport;
84             ///Gets the active viewport
85             Viewport function() getCurrentViewport;
86 
87             void function(bool bEnable) setStencilTestingEnabled;
88             void function(uint mask) setStencilTestingMask;
89             void function(ubyte r, ubyte g, ubyte b, ubyte a) setRendererColorMask;
90             void function(HipStencilTestingFunction passFunc, uint reference, uint mask) setStencilTestingFunction;
91             void function(HipStencilOperation stencilFail, HipStencilOperation depthFail, HipStencilOperation stencilAndDephPass) setStencilOperation;
92 
93             ///Width, Height
94             int[2] function() getWindowSize;
95 
96             void function(uint width, uint height) setWindowSize;
97             void function(uint width, uint height) setCameraSize;
98 
99             ///Creates a track for the animation controller
100             IHipAnimationTrack function(string name, uint framesPerSecond, HipAnimationLoopingMode loopingMode = HipAnimationLoopingMode.none) newHipAnimationTrack;
101             ///Creates an animation to be iterated 
102             IHipAnimation function(string name) newHipAnimation;
103 
104 
105             version(ImportSpritesheet)
106             {
107                 package Array2D_GC!IHipTextureRegion function(
108                     IHipTexture t,
109                     uint frameWidth, uint frameHeight,
110                     uint width = 0, uint height = 0,
111                     uint offsetX = 0, uint offsetY = 0,
112                     uint offsetXPerFrame = 0, uint offsetYPerFrame = 0
113                 ) cropSpritesheet;
114             }
115 
116         }
117     }
118 
119     version(ImportSpritesheet)
120     Array2D_GC!IHipTextureRegion cropSpritesheetRowsAndColumns(IHipTexture t, uint rows, uint columns)
121     {
122         uint frameWidth = t.getWidth() / columns;
123         uint frameHeight = t.getHeight() / rows;
124         return cropSpritesheet(t,frameWidth,frameHeight, t.getWidth, t.getHeight, 0, 0, 0, 0);
125     }
126     import hip.api.internal;
127     mixin ExpandClassFunctionPointers!HipG2DBinding;
128 }
129 
130 
131 //Code suggestion
132 version(none)
133 {
134     extern(System) __gshared //All functions there will be loaded
135     {
136         ///Use this only when you're sure you don't need!
137         void function(bool enable = true) setRendererErrorCheckingEnabled;
138 
139         ///Will change the color for the next calls to drawPixel, drawRectangle, drawTriangle, fillRectangle, fillTriangle, drawLine, drawQuadraticBezierLine
140         void function(in HipColor color) setGeometryColor;
141         ///Draw a pixel at (x, y) with the color specified at setGeometryColor
142         void function(int x, int y, in HipColor color = HipColor.no) drawPixel;
143         ///Draws an unfilled rectangle
144         void function(int x, int y, int w, int h, in HipColor color = HipColor.no) drawRectangle;
145         ///Draws an unfilled triangle
146         void function(int x1, int y1, int x2, int y2, int x3, int y3, in HipColor color = HipColor.no) drawTriangle;
147         ///Draws a filled rectangle
148         void function(int x, int y, int w, int h, in HipColor color = HipColor.no) fillRectangle;
149         ///Draws a filled rectangle with rounded borders
150         void function(int x, int y, int w, int h, int radius = 4, HipColor color = HipColor.no, int precision = 16) fillRoundRect;
151         ///Draws a filled triangle
152         void function(int x1, int y1, int x2, int y2, int x3, int y3, in HipColor color = HipColor.no) fillTriangle;
153         ///Draws unfilled circle
154         void function(int x, int y, int radiusW, int radiusH, int degrees = 360, in HipColor color = HipColor.no, int precision = 24) drawEllipse;
155         ///Draws a filled circle
156         void function(int x, int y, int radiusW, int radiusH, int degrees = 360, in HipColor color = HipColor.no, int precision = 24) fillEllipse;
157         ///Draws a line from (x1, y1) to (x2, y2)
158         void function(int x1, int y1, int x2, int y2, in HipColor color = HipColor.no) drawLine;
159         ///Draws a line using bezier points. The higher the precision, the smoother the line, the heavier it is to execute
160         void function(int x0, int y0, int x1, int y1, int x2, int y2, int precision=24, in HipColor color = HipColor.no) drawQuadraticBezierLine;
161         ///Draws the target sprite instance
162         void function(IHipTexture texture, ubyte[] vertices) drawSprite;
163         ///Draws a texture at a specified place
164         void function(IHipTexture reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawTexture;
165         ///Draws a texture region at a specified place
166         void function(IHipTextureRegion reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawRegion;
167         void function(IHipTilemap reg) drawMap;
168 
169         ///Changes textBatch state to use this color
170         void function(HipColor) setTextColor;
171         ///Sets the font for the next drawText commands
172         package void function (IHipFont font) setFont;
173         ///Sets the font using HipAssetManager.loadFont
174         package void function (IHipAssetLoadTask font) setFontDeferred;
175         ///Draws a text using the last font set
176         void function(string text, int x, int y, HipColor color = HipColor.white, HipTextAlign alignH = HipTextAlign.CENTER, HipTextAlign alignV = HipTextAlign.CENTER, int boundsWidth = -1, int boundsHeight = -1, bool wordWrap = false) drawText;
177         ///Draw text using those vertices. Low level API
178         void function(void[] vertices, IHipFont font)  drawTextVertices;
179         
180         ///Sets active the viewport passed
181         void function(Viewport v) setViewport;
182         ///Gets the active viewport
183         Viewport function() getCurrentViewport;
184         void function(bool bEnable) setStencilTestingEnabled;
185         void function(uint mask) setStencilTestingMask;
186         void function(ubyte r, ubyte g, ubyte b, ubyte a) setRendererColorMask;
187         void function(HipStencilTestingFunction passFunc, uint reference, uint mask) setStencilTestingFunction;
188         void function(HipStencilOperation stencilFail, HipStencilOperation depthFail, HipStencilOperation stencilAndDephPass) setStencilOperation;
189 
190         ///Width, Height
191         int[2] function() getWindowSize;
192 
193         void function(uint width, uint height) setWindowSize;
194 
195         void function(uint width, uint height) setCameraSize;
196 
197         ///Creates a track for the animation controller
198         IHipAnimationTrack function(string name, uint framesPerSecond, HipAnimationLoopingMode loopingMode = HipAnimationLoopingMode.none) newHipAnimationTrack;
199         ///Creates an animation to be iterated 
200         IHipAnimation function(string name) newHipAnimation;
201 
202 
203         version(ImportSpritesheet)
204         {
205             package Array2D_GC!IHipTextureRegion function(
206                 IHipTexture t,
207                 uint frameWidth, uint frameHeight,
208                 uint width = 0, uint height = 0,
209                 uint offsetX = 0, uint offsetY = 0,
210                 uint offsetXPerFrame = 0, uint offsetYPerFrame = 0
211             ) cropSpritesheet;
212         }
213 
214     }
215 }